package com.wat.cycleDI;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.BeansException;

import java.lang.reflect.Method;

//起床BPP处理器，只对 Mother 类返回advice
@SuppressWarnings("serial")
public class GetUpPostProcessor extends AbstractAutoProxyCreator {

	@Override
	protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource customTargetSource) throws BeansException {
		if (beanClass.equals(Mother.class)) {
			return new Object[]{new GetUpAdvice()};
		} else {
			return null;
		}
	}

	static class GetUpAdvice implements AfterReturningAdvice {
		@Override
		public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
			System.out.println("Hurry up! You will be late!");
		}
	}
}
